import pytest
import requests
@pytest.fixture(
    params=[
    {
        "casename": "验证输入正确的用户ID、标题、借款金额等条件均正常，加标成功",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 2,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 1,
            "code": "10001",
            "msg": "加标成功"
        }
    },
    {
        "casename": "验证memberld为1.234567890的输入",
        "data": {
            "memberId": 1.234567890,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 0,
            "repaymemtWay": 4,
            "biddingDays": 9
        },
        "expect": {
            "status": 0,
            "code": "20109",
            "msg": "请根据数值参数的类型对应输入合法的数字"
        }
    },
    {
        "casename": "验证memberld为1234567890@的输入",
        "data": {
            "memberId": "1234567890@",
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 0,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20109",
            "msg": "请根据数值参数的类型对应输入合法的数字"
        }
    },
    {
        "casename": "验证memberld为12345678999的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 2,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 1,
            "code": "10001",
            "msg": "加标成功"
        }
    },
    {
        "casename": "验证memberld为空的输入",
        "data": {
            "memberId": "",
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 0,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20103",
            "msg": "所有参数不能为空"
        }
    },
    {
        "casename": "验证title为空的输入",
        "data": {
            "memberId": 1,
            "title": "",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 0,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20103",
            "msg": "所有参数不能为空"
        }
    },
    {
        "casename": "验证amount为900的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 900,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 2,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20106",
            "msg": "参数错误：借款金额amount必须为大于等于1000并能被100整除的正整数"
        }
    },
    {
        "casename": "验证amount为1078的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1078,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 0,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20106",
            "msg": "参数错误：借款金额amount必须为大于1000并能被100整除的正整数"
        }
    },
    {
        "casename": "验证loanRate为-5的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": -5,
            "loanTerm": 6,
            "loanDateType": 0,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20107",
            "msg": "参数错误：借款利率loanRate值必须大于0小于或等于24"
        }
    },
    {
        "casename": "验证loanRate为25的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 25,
            "loanTerm": 6,
            "loanDateType": 2,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20107",
            "msg": "参数错误：借款利率loanRate值必须大于0小于或等于24"
        }
    },
    {
        "casename": "验证loanRate为@@的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": "@@",
            "loanTerm": 6,
            "loanDateType": 2,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20107",
            "msg": "参数错误：借款利率loanRate值必须大于0小于或等于24"
        }
    },
    {
        "casename": "验证loanRate为空的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": "",
            "loanTerm": 6,
            "loanDateType": 2,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20103",
            "msg": "所有参数不能为空"
        }
    },
    {
        "casename": "验证loanTerm为空的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": "",
            "loanDateType": 0,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20102",
            "msg": "参数不能为空"
        }
    },
    {
        "casename": "验证loanTerm为@的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": "@",
            "loanDateType": 0,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20109",
            "msg": "请根据数值参数的类型对应输入合法的数字"
        }
    },
    {
        "casename": "验证loanDateType为3的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 3,
            "repaymemtWay": 4,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20108",
            "msg": "参数错误：借款日期类型loanDateType只能为0,2,4"
        }
    },
    {
        "casename": "验证repaymemtWay为空的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 0,
            "repaymemtWay": "",
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20103",
            "msg": "参数不能为空"
        }
    },
    {
        "casename": "验证repaymemtWay为2的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 2,
            "repaymemtWay": 2,
            "biddingDays": 8
        },
        "expect": {
            "status": 0,
            "code": "20109",
            "msg": "还款方式repaymemtWay值无效"
        }
    },
    {
        "casename": "验证biddingDays为空的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 0,
            "repaymemtWay": 4,
            "biddingDays": ""
        },
        "expect": {
            "status": 0,
            "code": "20103",
            "msg": "所有参数不能为空"
        }
    },
    {
        "casename": "验证biddingDays为0的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 2,
            "repaymemtWay": 4,
            "biddingDays": 0
        },
        "expect": {
            "status": 0,
            "code": "20107",
            "msg": "竞标天数biddingDays值无效"
        }
    },
    {
        "casename": "验证biddingDays为11的输入",
        "data": {
            "memberId": 1,
            "title": "广告设计",
            "amount": 1000,
            "loanRate": 15,
            "loanTerm": 6,
            "loanDateType": 2,
            "repaymemtWay": 4,
            "biddingDays": 11
        },
        "expect": {
            "status": 0,
            "code": "20107",
            "msg": "竞标天数biddingDays值无效"
        }
    }
])

def add_data(request):  # 参数名是写死的，pytest规定好的，不能写错
    print("准备测试数据")
    # return request.param
    yield request.param  # 获取每一组的数据
    print("测试结束")

def test_add(add_data):  # login_data当作一个字典类型的变量
    r = requests.get("http://127.0.0.1:8088/futureloan/mvc/api/loan/add", params=add_data['data'])
    print(r.text)
    print(f"测试注册功能，用户ID为：{add_data['data']['memberId']}，标题为{add_data['data']['title']},数量为{add_data['data']['amount']}")
    a = r.json()
    assert a['status'] == add_data["expect"]['status']
    assert a['code'] == add_data["expect"]['code']
    assert a['msg'] == add_data["expect"]['msg']
